package com.xunshibao.core.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

import org.logicalcobwebs.proxool.ProxoolException;

public class ConnectionPool {
	private static ProxoolConnectionPool proxoolConnectionPool = null;;
	private static String connName = null;
	
	public static void configure(String file, String jndiName){
		connName = jndiName;
		Set<String> set = new HashSet<String>();
		set.add(file);
		try {
			proxoolConnectionPool = new ProxoolConnectionPool(set);
		} catch (ProxoolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection(){
		try {
			return proxoolConnectionPool.getConnection(connName);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 关闭连接
	 * @param conn
	 * @throws SQLException
	 */
	public static void closeConn(Connection conn){
		if (conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
